﻿@using QqhrCitizen.Models
@using QqhrCitizen.Models.ViewModel
@{
    Lession lession = ViewBag.Lession as Lession;
    List<vNote> listNote = ViewBag.ListNote as List<vNote>;
    List<vQuestion> questions = ViewBag.Questions as List<vQuestion>;
    bool flag = ViewBag.Flag;
    ViewBag.Title = lession.Title;
}

<script>
    $("#topmenu_course").attr("class", "item_selected");
</script>
<script src="~/Scripts/video.js"></script>
<script src="~/Scripts/alertify.js"></script>
<script src="~/Scripts/jquery.timers-1.2.js"></script>
<link rel="stylesheet" href="~/Styles/alertify.css" />
<link rel="stylesheet" href="~/Styles/alertify-bootstrap.css" />
<link rel="stylesheet" href="~/Styles/alertify-bootstrap-3.css" />
<script src="~/Scripts/ckeditor/ckeditor.js"></script>
<div id="d_menu" class="d-menu menu-cou">
    <div id="d_menu_c" class="d-menu-c">
        <!-- region start: menu -->
        <div id="d_headmenu" class="d-headmenu">

            <div class="body">
                <a id="headmenu_default" class="item" href="/Course/Index" target="_parent">课程首页</a>
                <a id="headmenu_discovery" class="item" href="/Course/Discovery/0" target="_parent">发现课程</a>
            </div>
        </div>
        <!-- region end: menu -->
    </div>
</div>

<div id="d_main" class="d-main" style="min-width: 1000px;">
    <div class="container">
        <div class="d-row" style="padding: 20px 0 0 0;">
            <div class="d-row-c">
                <div class="d-col-2-8">
                    <div class="contentarea">
                        <!-- region start: 课程信息 -->
                        <div id="d_coursedetail" class="d-coursedetail" width="600" height="400">
                            <h2>@lession.Title</h2>
                            <input type="hidden" id="hdCurrentuser" value="@(ViewBag.CurrentUser!=null? @ViewBag.CurrentUser.Username:"")" />
                            <input type="hidden" name="name" id="LessionID" value="@lession.ID" />
                            @if (flag == true)
                            {
                                <iframe src="@lession.Path" width="600" height="400"></iframe>
                            }
                            else
                            {
                                if (lession.Path.ToString().Substring(lession.Path.ToString().Length - 3, 3) != "wmv")
                                {
                                    <div id="a1"></div>
                                    <script type="text/javascript" src="~/Scripts/ckplayer/ckplayer.js" charset="utf-8"></script>
                                    <script type="text/javascript">
                                        var flashvars = {
                                            f: '@((int)ViewBag.CurrentRoute==1?lession.Path:lession.SecondPath)',
                                            c: 0
                                        };
                                        var params = { bgcolor: '#FFF', allowFullScreen: true, allowScriptAccess: 'always', wmode: 'transparent' };
                                        var video = ['@lession.Path'];
                                        CKobject.embed('/Scripts/ckplayer/ckplayer.swf', 'a1', 'ckplayer_a1', '600', '400', false, flashvars, video, params);
                                    </script>
                                }
                            }
                        </div>
                        <div style="width:600px;height:400px;background-color:#ffffff;position: absolute;top: 34px;z-index:1000;display:none" id="video-hidden">

                        </div>
                        <div style="margin:10px 0 10px;">
                            @for (int i = 1; i <= (int?)ViewBag.RouteCount; i++)
                            {
                              <a href="/Course/LessionDetails/@lession.ID?route=@i" style="color:@(i==(int)ViewBag.CurrentRoute?"red":"")">@CommonEnums.RouteDisplay[i]</a> 
                            }
                        </div>
                        <hr style="border: none; height: 1px; background-color: #ccc; margin: 20px 25px 0 0;">
                        <div id="d_courseware" class="d-courseware">
                            <div class="head">
                                课堂笔记
                            </div>
                            <div class="body">
                                <input type="hidden" id="userId" name="UserID" value="@(ViewBag.CurrentUser==null?" ":@ViewBag.CurrentUser.ID)" />
                                <input type="hidden" name="LessionID" id="LessionID" value="@lession.ID" />
                                <input type="hidden" id="sid" value="@ViewBag.SID" />
                                <textarea name="Content" class="textbox" id="noteContent"></textarea>
                                <p><input type="button" value="保存" id="btnAddNote" class="btn btn-orange btn-big" style="margin-left:10px;width:100px" /></p>
                                <div style="padding-top:10px;"><h5>历史笔记</h5></div>
                                <div id="lstNote">
                                    @if (listNote != null)
                                    {
                                        foreach (var note in listNote)
                                        {
                                            <div class="div_HisNote">
                                                @Html.Sanitized(@note.Content)
                                                <br />
                                                <span style="color:#808080;font-size:14px;text-align:right;margin-right:10px">@note.Time</span>
                                            </div>
                                        }
                                    }
                                </div>
                            </div>
                        </div>
                        <hr style="border: none; height: 1px; background-color: #ccc; margin: 20px 25px 0 0;">
                        <div id="d_courseware" class="d-courseware">
                            <div class="head">
                                课后问题
                            </div>
                            <div class="body">

                                @if (questions.Count() == 0)
                                {
                                    <p style="position:absolute; bottom:10px;text-align:center;width:1000px;color:#00a000">
                                        暂无课后问题
                                    </p>
                                }
                                else
                                {
                                    <input type="hidden" id="questionCount" value="@questions.Count" />
                                    for (int i = 0; i < questions.Count(); i++)
                                    {
                                        <div class="question" style="font-size:16px">
                                            @(i + 1)<span>.</span>@questions[i].Content <br />
                                            <input value="@questions[i].RightAnswer" type="hidden" class="roghtanswer" />
                                            @for (int j = 0; j < questions[i].Answers.Count(); j++)
                                            {
                                                <div class="radio"><label><input name="answer@(i+1)" type="radio" value="@j" class="answer" />@CommonEnums.Answers[j] : @questions[i].Answers[j]</label></div>
                                            }
                                        </div>

                                    }
                                    <input type="button" class="btn btn-orange btn-big" value="提交" style="width:100px;margin-bottom:10px" id="btnAnswerQuestion" />

                                }
                                <div class="warning"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="d-col-2-4">
                    <div class="contentarea">
                        <div id="Record" class="d-courseaction well">
                            <h2>课时</h2>
                            @foreach (var item in ViewBag.Lessions as List<vLession>)
                            {
                                <p><a href="/Course/LessionDetails/@item.ID">[@item.Time.ToString("yyyy-MM-dd")] @item.Title</a></p>
                            }
                        </div>
                        <div class="d-courseaction well">
                            <a href="/Course/Test/@lession.CourseID">课程测试</a>
                        </div>
                    </div>

                </div>
                <div class="clear"></div>
            </div>
        </div>
    </div>
</div>

<script>
    @*window.onbeforeunload = onbeforeunload_handler;
    window.onunload = onunload_handler;
    function onbeforeunload_handler() {
        var warning = "确认退出?";
        return warning;
    }
    function onunload_handler() {
        var user = $("#hdCurrentuser").val();
        alert(user);
        if (user != null && user != "") {
            $.post("/Course/LearningRecord/@lession.ID", function (data) {
            });
        }
    }*@

    window.onbeforeunload = onbeforeunload_handler;
    window.onunload = onunload_handler;
    function onbeforeunload_handler() {
        if (event.clientX > document.body.clientWidth && event.clientY < 0 || event.altKey) {
            alert("你关闭了浏览器");
        } else {
            alert("你正在刷新页面");
        }
    }

    //function onbeforeunload_handler() {
    //    if (document.body.clientWidth-event.clientX<21||event.altKey||event.ctrlKey){
    //        alert("close");
    //    }else{
    //        window.event.returnValue="";
    //        alert("refrash");
    //        return false;
    //    }
    //}

    function onunload_handler() {
        var user = $("#hdCurrentuser").val();
        //alert(user);
        if (user != null && user != "") {
            $.post("/Course/LearningRecord/@lession.ID", function (data) {
            });
        }
    }

    @*$(function () {
        $(window).unbind().bind('beforeunload', function () {
            if (document.body.clientWidth - event.clientX < 21 || event.altKey || event.ctrlKey) {
                alert("close");
            } else {
                window.event.returnValue = "";
                alert("refrash");
                return false;
            }
        })
        $(window).unbind().bind('onunload', function () {
            var user = $("#hdCurrentuser").val();
            alert(user);
            if (user != null && user != "") {
                $.post("/Course/LearningRecord/@lession.ID", function (data) {
                });
            }
        })


    })*@

    CKEDITOR.replace('Content',
    {
        toolbar: 'Basic',
        width: "100%",
        height: "80px"
    });
    $(function () {
        reset = function () {
            alertify.set({
                labels: {
                    ok: "继续",
                    cancel: "取消"
                },
                delay: 5000,
                buttonReverse: false,
                buttonFocus: "ok"
            });
        };
        var myVar = setTimeout(playorpause, 300000);
        function playorpause() {
            reset();
            $("#video-hidden").show();
            if (typeof (CKobject) != "undefined") {
                CKobject.getObjectById('ckplayer_a1').videoPause();
            }
            alertify.confirm("确认框", function (e) {
                if (e) {
                    alertify.success("点击确认");
                    if (typeof (CKobject) != "undefined") {
                        CKobject.getObjectById('ckplayer_a1').videoPlay();
                    }
                    $("#video-hidden").hide();
                    myVar = setTimeout(playorpause, 300000);
                } else {
                    alertify.error("点击取消");
                    if (typeof (CKobject) != "undefined") {
                        CKobject.getObjectById('ckplayer_a1').videoPause();
                    }
                    clearInterval(myVar);
                    $("#video-hidden").show();
                }
            });
        }
    });
</script>
